package com.yuexun.beilunpatient.ui.registration.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.baselistener.ICallBackListener;
import com.yuexun.beilunpatient.ui.registration.bean.ArrageViewData;
import com.yuexun.beilunpatient.utils.DateUtil;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;

/**
 * Created by chenss on 2018/10/18.
 */
public class DocSchedualAdapter extends KJAdapter<ArrageViewData> {

    ICallBackListener listener;

    public void setListener(ICallBackListener listener) {
        this.listener = listener;
    }

    public DocSchedualAdapter(AbsListView view, Collection<ArrageViewData> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder helper, ArrageViewData item, boolean isScrolling, final int position) {
        super.convert(helper, item, isScrolling, position);
        TextView tv_registration = (TextView) helper.getView(R.id.tv_registration);
        helper.setText(R.id.tv_date, item.getSchedule_date());
        try {
            String week = DateUtil.getDayOfWeek(new SimpleDateFormat("yyyy-MM-dd").parse(item.getSchedule_date()));
            if(item.getOut_time().equals("A")){
                helper.setText(R.id.tv_week, week + "上午");
            }else if(item.getOut_time().equals("P")){
                helper.setText(R.id.tv_week, week + "下午");
            }else if(item.getOut_time().equals("F")){
                helper.setText(R.id.tv_week, week + "全天");
            }else if(item.getOut_time().equals("N")){
                helper.setText(R.id.tv_week, week + "夜间");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        helper.setText(R.id.num, item.getRated_num());
        helper.setText(R.id.registration_fee, item.getReg_fee());
        helper.setText(R.id.consultation_fee, item.getClinic_fee());
        if(item.getRated_num().equals("0")){
            tv_registration.setEnabled(false);
            tv_registration.setBackgroundResource(R.drawable.send_gray_shape);
        }else{
            tv_registration.setEnabled(true);
            tv_registration.setBackgroundResource(R.drawable.blue_bg_circle_angle);
        }

        tv_registration.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putInt("position", position);
                listener.callback(bundle);
            }
        });
    }
}
